package com.hxh.tess4j.product;

import com.alibaba.fastjson.JSONObject;
import com.hxh.tess4j.util.OkhttpUtil;
import lombok.Data;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;

/**
 * @author huangxunhui
 * Date: Created in 2019-04-16 17:53
 * Utils: Intellij Idea
 * Description:
 */
public class GetProduct {

    public static void getProduct() throws IOException {
        File file = new File("/Users/code/IdeaProjects/tess4j/src/main/resources/product/product.txt");
        Writer out = new FileWriter(file);
        GetForm getForm = new GetForm();

        String url = "http://dc.zwqlcm.com/admin/product/listProduct";

        String ret = OkhttpUtil.postJsonParams(url, JSONObject.toJSONString(getForm));
        ProductListVo productListVo = JSONObject.parseObject(ret, ProductListVo.class);
        productListVo.getInfos().forEach(productVo ->{
            try {
                out.write(productVo.getName()+ "  link:"+ productVo.getLink() +", \n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }

    public static void main(String[] args) throws IOException {
        getProduct();
    }


}

@Data
class GetForm{


    private Integer enableFlag = 0;

    private Integer pageNo = 1;

    private Integer pageSize = 1000;

    private String token = "fecb97f443de003e20cfd5447607fdba";

    private Integer operatorId = 12;

}

@Data
class ProductListVo{

    private List<ProductVo> infos;

}

@Data
class ProductVo{

    private String name;

    private String link;

}
